$(function () {
    $("#btn1").click(function () {
        $.post("../oldman/findAllOldman", '', rs => {
            var str = "<option></option>"
            if (rs.code == 200) {
                $.each(rs.data, function (index, item) {
                    str += "<option value='" + item.oid + "'>" + item.oname + "</option>"
                });
                $(".hoid").html(str);
            }
        });
        $(".tts").css({display: 'block', opacity: '1', zIndex: '6'});
        $(".mask").css({display: 'block'});
    });
    $("#btn2").click(function () {
        $("#myform").attr("action", "../oldman/addHealth");
        $("#myform").submit();
    });
    $("#myform").ajaxForm(function (data) {
        if (data.code == 200) {
            cancelData();
            window.location.reload();
        }
    });
});
function editor(obj){
    $(".tts").css({display: 'block', opacity: '1', zIndex: '6'});
    $(".mask").css({display: 'block'});
    $(".disab").removeClass("show");
    var hid = $(obj).parent().siblings().eq(0).text();
    var healths = app.$data.healths;
    $.each(healths,function (index,item){
        if (item.hid == hid){
            $(".hid").val(item.hid);
            $(".hoid").html("<option value='"+item.hoid+"'>"+item.honame+"</option>");
            $(".hstatus").val(item.hstatus);
            $(".htep").val(item.htep);
            $(".hmessage").val(item.hmessage);
            $(".hdate").val(item.hdate);
        }
    });
};

function del(obj){
    var hid = $(obj).parent().siblings().eq(0).text();
    $.post("/oldman/delHealthById",qs.stringify({hid:hid}),rs => {
       if (rs.code == 200){
           window.location.reload();
       }
    });
}
function cancelData() {
    //更新数据的框关闭
    $(".tts").css({display: 'none'});
    //蒙版消失
    $(".mask").css({display: 'none'});
};
//设置码，由于是第一次，就设为1，后面根据情况，代码自动修改
var pageNum = 1;
//每页显示数量
var rows = 2;

//点击页码是，会去重新查找数据
function showToPage(obj) {
    $(obj).addClass('current').siblings().removeClass('current');
    var startNum = ($(obj).text() - 1) * rows;
    axios.post("../oldman/showToPage", qs.stringify({startNum: startNum, rows: rows})).then(rs => {
        if (rs.status == 200) {
            if (rs.data.code == 200) {
                app.$data.healths = rs.data.data;
            }
        }
    });
}
let app = new Vue({
    el: "#first2",
    data: {
        healths: {},
        totalPage: 1//页数
    },
    mounted: function () {
        this.findAllHealth();
    },
    methods: {
        findAllHealth: function () {
            axios.post("/oldman/findAllHealth",qs.stringify({startNum: 0, rows: rows})).then(rs => {
                if (rs.status == 200) {
                    if (rs.data.code == 200) {
                        this.healths = rs.data.data;
                        this.findTotoal();
                    }
                }
            })
        },
        findTotoal: function () {
            axios.post("../oldman/findTotal").then(rs => {
                this.totalPage = rs.data.data;
                $("#pagination").showPage(Math.ceil(this.totalPage / rows) || 1);
            });
        }
    }
});